<template>
    <div>
        <!-- 展示查询数据 -->
        <el-table :data="ObdList" style="width: 100%">
            <el-table-column prop="obdId" label="出库申请编号" ></el-table-column>
            <el-table-column prop="obdTime" label="出库时间" ></el-table-column>
            <el-table-column prop="statusStr" label="状态" >
                <template v-slot="scope">
                    <el-select v-model="scope.row.obdStatus" placeholder="状态"  @change="updateObdStatus(scope.row)">
                        <el-option
                                v-for="item in statusStrList"
                                :key="item.id"
                                :label="item.statusStr"
                                :value="item.id">
                        </el-option>
                    </el-select>

                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template v-slot="scope">
                    <el-button type="text" @click="handleDetail(scope.row)">查看详情</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 查看详情的对话框 -->
        <el-dialog title="商品详情" v-model="dialogVisible">
            <el-table :data="detailList">
                <el-table-column prop="brand" label="商品品牌"></el-table-column>
                <el-table-column prop="productName" label="商品名称"></el-table-column>
                <el-table-column prop="typeName" label="包装类型"></el-table-column>
                <el-table-column prop="weight" label="体积/重量"></el-table-column>
                <el-table-column prop="price" label="进货价"></el-table-column>
                <el-table-column prop="total" label="数量"></el-table-column>
            </el-table>
            <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">关闭</el-button>
        </span>
            </template>
        </el-dialog>

    </div>
</template>

<script setup>
    import {onMounted, reactive, ref} from 'vue'
    import {selectObd,updateObd} from "@/api/sale/obdDelivery";
    import {getOrdinaryEmployees} from  '@/api/warehouse/invInventory'
    const detailList = ref([])
    const ObdList=ref([])
    const time=ref('')
    const inventoryTakers = ref([]);
    const dialogVisible = ref(false);
    const params = ref();

    function updateObdStatus(row) {
        const params = {
            obdId:row.obdId,
            userId:row.userId,
            obdStatus:row.obdStatus,
        }
        console.log("row.obdStatus:"+row.obdStatus)
        updateObd(params).then(res =>{
            handleSearch();
            alert("修改成功")
            console.log("修改成功")
        }).catch(error => {
            console.error('修改状态失败:', error);
            // 错误处理逻辑
        });
    }

    const statusStrList = ref([
        {id:0,statusStr:"待出库"},
        {id:1,statusStr:"部分退货"},
        {id:2,statusStr:"退货"},
        {id:3,statusStr:"已出库"},
    ])


    handleSearch();
    function handleSearch(){
        selectObd().then(res=>{
            console.log(res)
            ObdList.value=res.obdDeliveryVoList;
            ObdList.value.forEach(item=>{
                item.obdTime=formatDate(new Date(item.obdTime));
            })
            console.log("ObdList:"+ObdList.value)
        })

    }
    const formatDate = (date) => {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以加1
        const day = String(date.getDate()).padStart(2, '0');
        return `${year}-${month}-${day}`;
    };
    // 查看详情
    const handleDetail = (row) => {
        console.log("row:"+row)
        detailList.value = [];
        row.saleOrderItemList.forEach(item=>{
            detailList.value.push(item)
        })
        dialogVisible.value = true
    }
    onMounted(() => {
        // 初始化逻辑
        //fetchInventoryTakers()
    });



</script>

<style scoped>
    /* 可以在这里添加一些样式 */
</style>
